// app.js
App({
  globalData: {
    zhuohao: null,
    openid: null,
  },
  //小程序一启动，就会执行
  onLaunch() {
    wx.cloud.init({
      env: 'food-manger-2g25txjo08dbbbdd' //云开发环境id

    })
    this.getopenid()
  },
  // 获取用户的openid
  getopenid() {
    wx.cloud.callFunction({
      name: 'getOpenid',
    }).then(res => {
      console.log('云函数获取用户的openid', res.result.openid)
      this.globalData.openid = res.result.openid
    })
  },
  // 获取当前时间
  getCurrentTime() {
    let d = new Date();
    let month = d.getMonth() + 1;
    let date = d.getDate();
    let hours = d.getHours();
    let minutes = d.getMinutes();

    let curDateTime = d.getFullYear() + '年';
    if (month > 9)
      curDateTime += month + '月';
    else
      curDateTime += month + '月';

    if (date > 9)
      curDateTime = curDateTime + date + "日";
    else
      curDateTime = curDateTime + date + "日";
    if (hours > 9)
      curDateTime = curDateTime + hours + "时";
    else
      curDateTime = curDateTime + hours + "时";
    if (minutes > 9)
      curDateTime = curDateTime + minutes + "分";
    else
      curDateTime = curDateTime + minutes + "分";
    return curDateTime;
  },

  // 只获取年月日,而且是纯数据
  getCurrentYMD() {
    let d = new Date();
    let month = d.getMonth() + 1;
    let date = d.getDate();
    let year = d.getFullYear();
    let time = "" + year + month + date;
    return time;
  },
  // 只获取年月日
  getCurrentYMDStr() {
    let d = new Date();
    let month = d.getMonth() + 1;
    let date = d.getDate();
    let year = d.getFullYear();
    let time = year + "年" + month + "月" + date + "日";
    return time;
  },
  // 获取当前的月份
  _getMonth() {
    let date = new Date()
    // 我们的月份是从0开始的 0代表1月份，11代表12月
    let month = date.getMonth() + 1
    return month
  },
})